package com.veeder.datacollection.log;

import java.util.*;
import java.text.*;
import java.util.logging.*;

/**
 * PlainTextFormatter formats LogRecord objects into plain-text
 * strings that have the same style as the log messages produced
 * by the TLS.
 */
public class PlainTextFormatter extends java.util.logging.Formatter {
	/**
	 * Format a given LogRecord object into a TLS-style log string.
	 *
	 * @param r a non-null LogRecord object reference
	 * @return a String containing the formatted log message
	 */
	public String format(LogRecord r) {
		if (r == null)
			throw new IllegalArgumentException("LogRecord reference must be non-null");
		Date ts = new Date(r.getMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		return String.format("%s [%s/%s] %s%n", sdf.format(ts), r.getLoggerName(),
			r.getLevel(), r.getMessage());
	}
}